'use strict';
const uniID = require('uni-id-common')
exports.main = async (event, context) => {
	const db = uniCloud.databaseForJQL({
			event,
			context 
		});
		const uniIDIns = uniID.createInstance({
			context: context,
		})
		db.setUser({
			role: ['admin']
		})
		const res = await uniIDIns.checkToken(event.uniIdToken)
		const userinfo=await db.collection("uni-id-users").where({_id:event.id}).get();
		if(userinfo.data.length==0){
			return {code:400,msg:"绑定失败"}
		}
		console.log(userinfo.data[0]);
		var username=userinfo.data[0].username
		var password=userinfo.data[0].password
		const resd=await db.collection("uni-id-users").where({_id:event.user_id}).update({username:username,password:password});
		await db.collection("uni-id-users").where({_id:event.id}).remove()
		return {code:200,msg:"绑定成功"}
};
